package com.youlu.campus.service.system.impl;

import com.youlu.campus.entity.SystemId;
import com.youlu.campus.service.system.SystemIdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class SystemIdServiceImpl implements SystemIdService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public String generateId() {
        log.info(":>>> 开始生成ID");
        SystemId systemId = new SystemId();
        systemId.setId(null);
        systemId.setCreatedTime(new Date());
        systemId = mongoTemplate.insert(systemId);
        log.info(":>>> 生成的ID:{}", systemId.getId());
        return systemId.getId();
    }
}
